import Base from '@/common/js/common.js'
import request from '@/common/js/common/request.js'

// 登录方法
export function login(username, password) {
	const data = {
		username,
		password
	}
	return request({
		url: '/login',
		method: 'post',
		data: data
	})
}

export function wxLogin(userInfo, code) {
	const params = {
		'openId': userInfo.openId,
		'code': code,
		'errMsg': userInfo.errMsg,
		'rawData': userInfo.rawData,
		'encryptedData': userInfo.encryptedData,
		'iv': userInfo.iv,
		'signature': userInfo.signature,
		'userInfo': userInfo.userInfo,
	}
	return request({
		url: '/wxLogin',
		method: 'post',
		data: params
	})
}

// 获取用户详细信息
export function getInfo() {
	return request({
		url: '/getInfo',
		method: 'get'
	})
}

// 退出登录
export function logout() {
	uni.setStorageSync("token", "");
	Base.gotoView("/pages/login/login")
}

// 用户密码重置
export function resetUserPwd(oldPassword, newPassword) {
	const data = {
		oldPassword,
		newPassword
	}
	return request({
		url: '/system/user/profile/updatePwd',
		method: 'put',
		params: data
	})
}

export function listUser(query) {
	return request({
		url: '/system/user/list',
		method: 'get',
		params: query
	})
}
WW
export function listUserServicer(query) {
	return request({
		url: '/app/system/user/list',
		method: 'get',
		params: query
	})
}

// 通过电话号码获取用户详细信息
export function getUser(phoneNumber) {
    return request({
        url: '/app/system/user/' + phoneNumber,
        method: 'get'
    })
}